﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security;
using System.Security.Cryptography;
using System.IO;

namespace PFMHandlers
{
   
    public  class PFMEncodeHandler:PFMHandler
    {
        
        public  byte []  PFMEncode(byte[] Encode)
        {
            PFMGlobals.PFMDefinitions.param = new CspParameters();
            PFMGlobals.PFMDefinitions.param.KeyContainerName = "Olive";//密匙容器的名称，保持加密解密一致才能解密成功
            using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(PFMGlobals.PFMDefinitions.param))
            {
                //byte[] plaindata = Encoding.Default.GetBytes(txtyuan.Text);//将要加密的字符串转换为字节数组
                return rsa.Encrypt(Encode, false);//将加密后的字节数据转换为新的加密字节数组
                //txtjiami.Text = Convert.ToBase64String(encryptdata);//将加密后的字节数组转换为字符串
            }

            //MemoryStream ms = new MemoryStream();//先创建 一个内存流
            //CryptoStream cryStream = new CryptoStream(ms,PFMGlobals.PFMDefinitions.DesCSP.CreateEncryptor(), CryptoStreamMode.Write);//将内存流连接到加密转换流
            //StreamWriter sw = new StreamWriter(cryStream);
            ////string  b = Convert.ToBase64String(Encode));
            //sw.WriteLine(PFMGlobals.PFMDefinitions.strLine);//将要加密的字符串写入加密转换流
            //sw.Close();
            //cryStream.Close();
            //PFMGlobals.PFMDefinitions.buffer = ms.ToArray(); //将加密后的流转换为字节数组
            //return PFMGlobals.PFMDefinitions.buffer; 
            
        }
       

    }
}
